// 国际化配置组件
<template>
  <el-config-provider :locale="locale">
    <slot></slot>
  </el-config-provider>
</template>

<script setup lang="ts">
  import { ref, watchEffect } from 'vue'
  import { useI18n } from 'vue-i18n'
  import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
  import en from 'element-plus/dist/locale/en.mjs'

  // 获取i18n实例
  const { locale: i18nLocale } = useI18n()

  // Element Plus 语言包
  const locale = ref(zhCn)

  // 监听语言变化，同步更新 Element Plus 的语言设置
  watchEffect(() => {
    locale.value = i18nLocale.value === 'zh-CN' ? zhCn : en
  })
</script>
